package 面试题;

import java.util.Stack;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: MENG
 * Date: 2022-07-12
 * Time: 19:22
 */
//用栈实现队列
public class MyQueue {
        Stack<Integer> s1;
        Stack<Integer> s2;

    public MyQueue() {
        this.s1 = new Stack<>();
        this.s2 = new Stack<>();
    }

    public boolean empty(){
        return s1.empty() && s2.empty();
    }
    public void push(int x) {
        s1.push(x);
    }

    public int pop(){
        if(empty()){
            return -1;
        }
        if(s2.empty()){
            while(!s1.empty()){
                s2.push(s1.pop());
            }
        }
        return s2.pop();
    }
    public int peek(){
        if(empty()){
            return -1;
        }
        if(s2.empty()){
            while(!s1.empty()){
                s2.push(s1.pop());
            }
        }
        return s2.peek();
    }

}